package com.yidiandao.business.ui.main.shoppingcart.inventory;

import com.yidiandao.business.data.model.IConfirmOrderModel;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.view.SuperLoadingLayout;

import java.util.List;

/**
 * 确认订单-商品列表-Presenter
 */
public class InventoryPresenter implements InventoryContract.Presenter {

    private InventoryContract.View mConfirmOrderGoodsView;

    private IConfirmOrderModel mConfirmOrderModel;

    public InventoryPresenter(
            InventoryContract.View view, IConfirmOrderModel confirmOrderModel) {
        mConfirmOrderGoodsView = view;
        mConfirmOrderModel = confirmOrderModel;

        mConfirmOrderGoodsView.setPresenter(this);
    }

    @Override
    public void start() {
        mConfirmOrderModel.loadInventory(mConfirmOrderGoodsView.getPagerTag(),
                new IConfirmOrderModel.OnInventoryListener() {
                    @Override
                    public void onSuccess(List<DisplayListItem> displayListItems, int total) {
                        mConfirmOrderGoodsView.refreshContent(mConfirmOrderGoodsView.checkResultObject(displayListItems));
                        mConfirmOrderGoodsView.setDisplayListItems(displayListItems);

                        mConfirmOrderGoodsView.setTotalNumber(total);
                    }

                    @Override
                    public void onFailed() {
                        mConfirmOrderGoodsView.refreshContent(SuperLoadingLayout.STATE_ERROR);
                    }
                });
    }
}
